import './tabs/home.dart';
import 'tabs/sort.dart';
import './tabs/settings.dart';
import './tabs/fifth.dart';
import './tabs/mine.dart';
import 'package:flutter/material.dart';

class Tabs extends StatefulWidget {
  const Tabs({super.key});

  @override
  State<Tabs> createState() => _TabsState();
}

class _TabsState extends State<Tabs> {
  int _currIndex = 0;

  final List<Widget> _pages = const [
    HomePage(),
    Sort(),
    Setting(),
    Mine(),
    Fifth(),
    HomePage(),
    Fifth(),
  ];

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text("P33b")),
      body: _pages[_currIndex],
      bottomNavigationBar: BottomNavigationBar(
          showSelectedLabels: true,
          showUnselectedLabels: true,
          iconSize: 35,
          type: BottomNavigationBarType
              .fixed, //图标文字固定大小，BottomNavigationBarType.shifting选中的菜单图标文字会放大
          unselectedItemColor: Colors.grey,
          currentIndex: _currIndex,
          onTap: (index) {
            setState(() {
              //执行setState会执行build
              _currIndex = index; //切换选中页
            });
          },
          items: const [
            BottomNavigationBarItem(
              icon: Icon(Icons.home),
              label: "首页",
            ),
            BottomNavigationBarItem(icon: Icon(Icons.category), label: "分类"),
            BottomNavigationBarItem(icon: Icon(Icons.settings), label: "设置"),
            BottomNavigationBarItem(icon: Icon(Icons.person), label: "我的"),
            BottomNavigationBarItem(icon: Icon(Icons.fifteen_mp), label: "第五"),
            BottomNavigationBarItem(icon: Icon(Icons.six_k), label: "第6"),
            BottomNavigationBarItem(icon: Icon(Icons.seven_k), label: "第7"),
          ]),
    );
  }
}
